package work.array;

public class Problem189 {

    public void rotate(int[] nums, int k) {
        int length = nums.length;
        if (k <= 0 || length == 1) return;
        if (k > length) k = k % length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);
    }

    public void reverse(int[] nums, int start, int end) {
        int num = (start + end) / 2;
        for (int i = start; i <= num; i++) {
            int temp = nums[i];
            nums[i] = nums[end + start - i];
            nums[end + start - i] = temp;
        }
    }

    public static void main(String[] args) {
        Problem189 problem189 = new Problem189();
        int[] ans = new int[]{1};
        problem189.rotate(ans, 0);
    }
}
